<?php

class SearchController extends Controller
{
	public function actionIndex()
	{
			
			//if(isset($_GET['Book']))
			//$model->attributes=$_GET['Book'];
			
			$this->render('index');
	}
	public function actionSearch()
	{
			$name = $_GET['name'];
			$genres = $_GET['genres'];
			$description = $_GET['description'];
			$author = $_GET['author'];
			$point = $_GET['point'];
			$option = $_GET['option'];
			$dc = 0;
			$condition = ' ';
			$condition = $condition.' point '.$option.' '.$point;
			if($genres != '8'){
			$condition = $condition.' and idbook in (select idbook from book_genre where idgenre ='.$genres.')';
			}
			if($name != ''){
			$condition = $condition.' and name like \'%'.$name.'%\'';
			}
			if($description != ''){
			$condition = $condition.' and description like \'%'.$description.'%\'';
			}
			if($author != ''){
			$condition = $condition.' and author like \'%'.$author.'%\'';
			}
			//echo $condition;
			//Yii::app()->end();
			$dataProvider=new CActiveDataProvider(Book::model(),
			array(
			'criteria'=>array(
				'condition'=>$condition,
				'limit'=>8;
				),
			'pagination'=>array(
			'pageSize'=>8,
    ),
			));
			$this->render('result',array('dataProvider'=>$dataProvider));
		
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}